package org.gw.building.util;

import org.gw.building.model.StuInfo;
import org.gw.building.repositories.StuInfoRepository;
import org.gw.ylc.base.context.RequestContext;
import org.gw.ylc.base.context.RequestContextHolder;
import org.gw.ylc.base.model.UserInfo;

import java.util.Arrays;
import java.util.List;

public class TrainUtil {
	public static StuInfo getCurrentStuInfo(StuInfoRepository repository,String termId) {
		String uid = RequestContextHolder.get().getUser().getUid();
		StuInfo stuInfo = repository.findOneByXhAndTerm(uid, termId);
		return stuInfo;
	}

	public static Integer getFilteredStatus(Integer status) {
		RequestContext context = RequestContextHolder.get();
		if (context != null) {
			UserInfo user = context.getUser();
			if (user.getType() > 1) {
				if (status == null || status < 2) {
					return 2;
				}
			}
		}
		return status;
	}

	public static String getFilteredStatusString(Integer status) {
		RequestContext context = RequestContextHolder.get();
		if (context != null) {
			UserInfo user = context.getUser();
			if (status == null) {
				if (user.getType() > 1) {
					return "2,3";
				}
				return "1,2,3";
			} else {
				return status + "";
			}
		}
		return null;
	}

	public static List<Integer> getFilteredStatusArray(Integer status) {
		RequestContext context = RequestContextHolder.get();
		if (context != null) {
			UserInfo user = context.getUser();
			if (status == null) {
				if (user.getType() > 1) {
					return Arrays.asList(2, 3);
				}
				return Arrays.asList(1, 2, 3);
			} else {
				return Arrays.asList(status);
			}
		}
		return Arrays.asList(1, 2, 3);
	}
}
